package game;

import java.awt.image.BufferedImage;

/**
 * @Author: liwan
 * @Description:
 * @Date: create in 2021/9/1/001 15:31:26
 */
public class Net extends Thread{
    private int x;
    private int y;
    private int w;
    private int h;
    private BufferedImage image;
    private GamePanel panel;

    public Net(GamePanel panel) {
        this.panel = panel;
        this.image = ImageUtil.getImg("../img/net_1.png");
        this.w = image.getWidth();
        this.h = image.getHeight();
        this.x = -1000;
        this.y = -1000;
    }

    /**
    * @Author: liwan
    * @Description: 修改渔网的大小
    * @Params: netSize 渔网的序号
    * @Return:
    * @DateTime: 2021/9/2 10:02:38
    */
    public void changeImg(int netSize) {
        this.image = ImageUtil.getImg("../img/net_" + netSize + ".png");
        this.w = image.getWidth();
        this.h = image.getHeight();
    }


    /**
    * @Author: liwan
    * @Description: 判断鱼是否在网内
    * @Params: fish 要判断的鱼
    * @Return: {@link boolean}
    * @DateTime: 2021/9/2 11:49:33
    */
    public boolean catchFish(Fish fish) {
        //满足横坐标
        boolean flage1 = fish.getX() > this.x - this.w / 2 && fish.getX() < this.x + this.w / 2;
        //满足纵坐标
        boolean flage2 = fish.getY() > this.y - this.h / 2 && fish.getY() < this.y + this.h / 2;
        return  flage1 && flage2;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getW() {
        return w;
    }

    public void setW(int w) {
        this.w = w;
    }

    public int getH() {
        return h;
    }

    public void setH(int h) {
        this.h = h;
    }

    public BufferedImage getImage() {
        return image;
    }

    public void setImage(BufferedImage image) {
        this.image = image;
    }


}
